
<?php 
if($_REQUEST['_a']=="d")
{
	$id = $_REQUEST['_d'];
	mysql_query("delete from classifieds_subcategory where id='$id'");
	//header("location:index.php?tc=news&page=$page&_s=2");
	
	echo "<script>window.location='index.php?tc=classifieds_subcategory&page=$page&_s=2'</script>";
}
?>
<form name="nnf" method="post" action="#">
<table border="0" width="100%" align="center">
<tr>
	<td width="46%" align="left"><span style="color:#1B78B7; font-size:14px; font-weight:bold">
    Classifieds Sub Category</span>&nbsp; 
	<!--<input type="button" name="addnew" value="Add New" onclick="return show();" />-->
	</td>
	<td width="40%" align="right" class="font12">
   <a href="index.php?tc=add_classifieds_subcat" class="font12">Add Sub Category</a>    
     <!--<a href="index.php?tc=add_classifieds_subcat" class="font12">Add sub category</a>--></td>
	<td width="14%" align="right"><select name="_st" onchange="window.location='index.php?tc=classifieds_subcategory&page=<?php echo $_REQUEST['page'];?>&_st='+this.value">
	  <option value="" <?php if($_REQUEST['_st']=="") echo "selected";?>><--Sort--></option>
	  <option value="2" <?php if($_REQUEST['_st']==2) echo "selected";?>>All</option>
	  <option value="1" <?php if($_REQUEST['_st']==1) echo "selected";?>>Approved Ads</option>
	  <option value="3" <?php if($_REQUEST['_st']==3) echo "selected";?>>Pending Ads</option>
	  </select></td>
</tr>
<tr>
	<td background="images/topline.gif" colspan="3" height="11"></td>
</tr>    
</table>
</form>
	<?php
if($_REQUEST['_s'] == 2)
{ ?>
	<table align="center" border="0">
	<tr>
    	<td align="center"><div class="sucmsg"><img src="images/information.png" align="absmiddle" />&nbsp;Deleted Successfully</div></td>
    </tr>    
    </table>
<?php } ?>
<?php
if($_REQUEST['_s'] == 1)
{ ?>
	<table align="center" border="0">
	<tr>
    	<td align="center"><div class="sucmsg"><img src="images/information.png" align="absmiddle" />&nbsp;Updated Successfully</div></td>
    </tr>    
    </table>
<?php } ?>
<table width="100%" align="center" border="0" class="list">
<thead>
<tr>
	<td align="center" width="30">#</td>
	<td align="center" >Category Name</td>
    <td align="center" >Sub Category Name</td>
    <td align="center" >Description</td>
     <td align="center">Status</td>
    <td align="center">Action</td>
</tr>
</thead>
<?php
include('includes/function.php');
$self="index.php?tc=classifieds_subcategory&_st=".$_REQUEST['_st'];
$rowsPerPage = 20;
$pageNum = 1;
if(isset($_GET['page']))
{
	$pageNum = $_GET['page'];
}
if($_GET['page']=="")
{
	$pageNum = 1;
}

/*<!--counting the offset-->*/
$offset = ($pageNum - 1) * $rowsPerPage;
$st = $_REQUEST['_st'];

if($st == "" || $st == 2)
{
	$res = mysql_query("select id from classifieds_subcategory");
	
	$query = mysql_query("SELECT j.category,js.id id,js.sub_cat_name,js.desc,js.active_status from 
classifieds_subcategory js INNER JOIN classifieds_category j ON j.id=js.category_id
order by js.id desc limit $offset , $rowsPerPage") or die(mysql_error());
}
else
{
	if($st == 3) $st=0;
	$res = mysql_query("select id from classifieds_subcategory where active_status='$st'");
	
	$query = mysql_query("SELECT j.category,js.id id,js.sub_cat_name,js.desc,js.active_status from 
classifieds_subcategory js INNER JOIN classifieds_category j ON j.id=js.category_id
where js.active_status='$st' order by js.id desc limit $offset , $rowsPerPage");
}
$i = 1;
while($q = mysql_fetch_array($query))
{ 
	if($q["active_status"] == 1) $status = "Approved";
	else $status = "Pending";
	?>
    <tr class="font12">
        <td align="center"><?php echo $i+$offset;?></td>
        <td align="left" width="200px;"><?php echo $q["category"];?></td>
         <td align="left" width="200px;"><?php echo $q["sub_cat_name"];?></td>
           <td align="left" width="300px;" title="<?php echo strip_tags($q["desc"]);?>"><?php echo stripslashes(substr($q["desc"],0,100));?></td>
       
         <td align="center"><?php echo $status;?></td>
        <td align="center"><a href="index.php?tc=add_classifieds_subcat&_d=<?php echo $q['id'];?>&page=<?php echo $pageNum;?>&m=edit" class="font12">Edit</a> | 
        	<a href="index.php?tc=classifieds_subcategory&_d=<?php echo $q['id'];?>&_a=d&page=<?php echo $pageNum;?>" onclick="return confirm('Are you sure want to delete?')" class="font12">Delete</a>
        </td>
   	</tr>     
<?php 
	$i++;
}
?>
<?php 
if(mysql_num_rows($res) <= $rowsPerPage){	}
else { ?>
<tr>
    <td colspan="7" align="center"  bgcolor="#E3ECF3">
        <?php echo $paginglink=getPagingLink($res, $rowsPerPage,$pageNum,$self); ?>	
    </td>
</tr>
<?php } ?>
</table>    